(function() {
	var utils = baidu.editor.utils;
	var Popup = baidu.editor.ui.Popup;
	var SplitButton = baidu.editor.ui.SplitButton;

	var TCalendar;
	var Tformat;

	(function() {
		var T, baidu = T = baidu || {
			version : "1.3.9"
		};
		baidu.guid = "$BAIDU$";
		window[baidu.guid] = window[baidu.guid] || {};
		baidu.ui = baidu.ui || {
			version : "1.3.9"
		};
		baidu.ui.getUI = function(c) {
			var c = c.split("-"), b = baidu.ui, a = c.length, d = 0;
			for (; d < a; d++) {
				b = b[c[d].charAt(0).toUpperCase() + c[d].slice(1)]
			}
			return b
		};
		baidu.lang = baidu.lang || {};
		baidu.lang.isString = function(a) {
			return "[object String]" == Object.prototype.toString.call(a)
		};
		baidu.isString = baidu.lang.isString;
		baidu.ui.create = function(b, a) {
			if (baidu.lang.isString(b)) {
				b = baidu.ui.getUI(b)
			}
			return new b(a)
		};
		baidu.dom = baidu.dom || {};
		baidu.dom.g = function(a) {
			if ("string" == typeof a || a instanceof String) {
				return document.getElementById(a)
			} else {
				if (a && a.nodeName && (a.nodeType == 1 || a.nodeType == 9)) {
					return a
				}
			}
			return null
		};
		baidu.g = baidu.G = baidu.dom.g;
		(function() {
			var a = window[baidu.guid];
			baidu.lang.guid = function() {
				return "TANGRAM__" + (a._counter++).toString(36)
			};
			a._counter = a._counter || 1
		})();
		window[baidu.guid]._instances = window[baidu.guid]._instances || {};
		baidu.lang.isFunction = function(a) {
			return "[object Function]" == Object.prototype.toString.call(a)
		};
		baidu.lang.Class = function(a) {
			this.guid = a || baidu.lang.guid();
			window[baidu.guid]._instances[this.guid] = this
		};
		window[baidu.guid]._instances = window[baidu.guid]._instances || {};
		baidu.lang.Class.prototype.dispose = function() {
			delete window[baidu.guid]._instances[this.guid];
			for (var a in this) {
				if (!baidu.lang.isFunction(this[a])) {
					delete this[a]
				}
			}
			this.disposed = true
		};
		baidu.lang.Class.prototype.toString = function() {
			return "[object " + (this._className || "Object") + "]"
		};
		baidu.lang.Event = function(a, b) {
			this.type = a;
			this.returnValue = true;
			this.target = b || null;
			this.currentTarget = null
		};
		baidu.lang.Class.prototype.addEventListener = function(d, c, b) {
			if (!baidu.lang.isFunction(c)) {
				return
			}
			!this.__listeners && (this.__listeners = {});
			var a = this.__listeners, e;
			if (typeof b == "string" && b) {
				if (/[^\w\-]/.test(b)) {
					throw ("nonstandard key:" + b)
				} else {
					c.hashCode = b;
					e = b
				}
			}
			d.indexOf("on") != 0 && (d = "on" + d);
			typeof a[d] != "object" && (a[d] = {});
			e = e || baidu.lang.guid();
			c.hashCode = e;
			a[d][e] = c
		};
		baidu.lang.Class.prototype.removeEventListener = function(d, c) {
			if (typeof c != "undefined") {
				if ((baidu.lang.isFunction(c) && !(c = c.hashCode))
						|| (!baidu.lang.isString(c))) {
					return
				}
			}
			!this.__listeners && (this.__listeners = {});
			d.indexOf("on") != 0 && (d = "on" + d);
			var b = this.__listeners;
			if (!b[d]) {
				return
			}
			if (typeof c != "undefined") {
				b[d][c] && delete b[d][c]
			} else {
				for (var a in b[d]) {
					delete b[d][a]
				}
			}
		};
		baidu.lang.Class.prototype.dispatchEvent = function(d, a) {
			if (baidu.lang.isString(d)) {
				d = new baidu.lang.Event(d)
			}
			!this.__listeners && (this.__listeners = {});
			a = a || {};
			for (var c in a) {
				d[c] = a[c]
			}
			var c, b = this.__listeners, e = d.type;
			d.target = d.target || this;
			d.currentTarget = this;
			e.indexOf("on") != 0 && (e = "on" + e);
			baidu.lang.isFunction(this[e]) && this[e].apply(this, arguments);
			if (typeof b[e] == "object") {
				for (c in b[e]) {
					b[e][c].apply(this, arguments)
				}
			}
			return d.returnValue
		};
		baidu.event = baidu.event || {};
		baidu.event._listeners = baidu.event._listeners || [];
		baidu.dom._g = function(a) {
			if (baidu.lang.isString(a)) {
				return document.getElementById(a)
			}
			return a
		};
		baidu._g = baidu.dom._g;
		baidu.event.on = function(b, e, g) {
			e = e.replace(/^on/i, "");
			b = baidu.dom._g(b);
			var f = function(i) {
				g.call(b, i)
			}, a = baidu.event._listeners, d = baidu.event._eventFilter, h, c = e;
			e = e.toLowerCase();
			if (d && d[e]) {
				h = d[e](b, e, f);
				c = h.type;
				f = h.listener
			}
			if (b.addEventListener) {
				b.addEventListener(c, f, false)
			} else {
				if (b.attachEvent) {
					b.attachEvent("on" + c, f)
				}
			}
			a[a.length] = [b, e, g, f, c];
			return b
		};
		baidu.on = baidu.event.on;
		baidu.event.un = function(c, f, b) {
			c = baidu.dom._g(c);
			f = f.replace(/^on/i, "").toLowerCase();
			var i = baidu.event._listeners, d = i.length, e = !b, h, g, a;
			while (d--) {
				h = i[d];
				if (h[1] === f && h[0] === c && (e || h[2] === b)) {
					g = h[4];
					a = h[3];
					if (c.removeEventListener) {
						c.removeEventListener(g, a, false)
					} else {
						if (c.detachEvent) {
							c.detachEvent("on" + g, a)
						}
					}
					i.splice(d, 1)
				}
			}
			return c
		};
		baidu.un = baidu.event.un;
		baidu.ui.Base = {
			id : "",
			getId : function(a) {
				var c = this, b;
				b = "tangram-" + c.uiType + "--" + (c.id ? c.id : c.guid);
				return a ? b + "-" + a : b
			},
			getClass : function(b) {
				var d = this, c = d.classPrefix, a = d.skin;
				if (b) {
					c += "-" + b;
					a += "-" + b
				}
				if (d.skin) {
					c += " " + a
				}
				return c
			},
			getMain : function() {
				return baidu.g(this.mainId)
			},
			getBody : function() {
				return baidu.g(this.getId())
			},
			uiType : "",
			getCallRef : function() {
				return "window['$BAIDU$']._instances['" + this.guid + "']"
			},
			getCallString : function(d) {
				var c = 0, b = Array.prototype.slice.call(arguments, 1), a = b.length;
				for (; c < a; c++) {
					if (typeof b[c] == "string") {
						b[c] = "'" + b[c] + "'"
					}
				}
				return this.getCallRef() + "." + d + "(" + b.join(",") + ");"
			},
			on : function(a, b, c) {
				baidu.on(a, b, c);
				this.addEventListener("ondispose", function() {
							baidu.un(a, b, c)
						})
			},
			renderMain : function(b) {
				var d = this, c = 0, a;
				if (d.getMain()) {
					return
				}
				b = baidu.g(b);
				if (!b) {
					b = document.createElement("div");
					document.body.appendChild(b);
					b.style.position = "absolute";
					b.className = d.getClass("main")
				}
				if (!b.id) {
					b.id = d.getId("main")
				}
				d.mainId = b.id;
				b.setAttribute("data-guid", d.guid);
				return b
			},
			dispose : function() {
				this.dispatchEvent("dispose");
				baidu.lang.Class.prototype.dispose.call(this)
			}
		};
		baidu.object = baidu.object || {};
		baidu.extend = baidu.object.extend = function(c, a) {
			for (var b in a) {
				if (a.hasOwnProperty(b)) {
					c[b] = a[b]
				}
			}
			return c
		};
		baidu.ui.createUI = function(c, j) {
			j = j || {};
			var g = j.superClass || baidu.lang.Class, f = g == baidu.lang.Class
					? 1
					: 0, d, b, h = function(k, i) {
				var l = this;
				k = k || {};
				g.call(l, !f ? k : (k.guid || ""), true);
				baidu.object.extend(l, h.options);
				baidu.object.extend(l, k);
				l.classPrefix = l.classPrefix || "tangram-"
						+ l.uiType.toLowerCase();
				for (d in baidu.ui.behavior) {
					if (typeof l[d] != "undefined" && l[d]) {
						baidu.object.extend(l, baidu.ui.behavior[d]);
						if (baidu.lang.isFunction(l[d])) {
							l.addEventListener("onload", function() {
										baidu.ui.behavior[d]
												.call(l[d].apply(l))
									})
						} else {
							baidu.ui.behavior[d].call(l)
						}
					}
				}
				c.apply(l, arguments);
				for (d = 0, b = h._addons.length; d < b; d++) {
					h._addons[d](l)
				}
				if (k.parent && l.setParent) {
					l.setParent(k.parent)
				}
				if (!i && k.autoRender) {
					l.render(k.element)
				}
			}, a = function() {
			};
			a.prototype = g.prototype;
			var e = h.prototype = new a();
			for (d in baidu.ui.Base) {
				e[d] = baidu.ui.Base[d]
			}
			h.extend = function(i) {
				for (d in i) {
					h.prototype[d] = i[d]
				}
				return h
			};
			h._addons = [];
			h.register = function(i) {
				if (typeof i == "function") {
					h._addons.push(i)
				}
			};
			h.options = {};
			return h
		};
		baidu.ui.behavior = baidu.ui.behavior || {};
		baidu.string = baidu.string || {};
		(function() {
			var a = new RegExp(
					"(^[\\s\\t\\xa0\\u3000]+)|([\\u3000\\xa0\\s\\t]+\x24)", "g");
			baidu.string.trim = function(b) {
				return String(b).replace(a, "")
			}
		})();
		baidu.trim = baidu.string.trim;
		baidu.dom.addClass = function(f, g) {
			f = baidu.dom.g(f);
			var b = g.split(/\s+/), a = f.className, e = " " + a + " ", d = 0, c = b.length;
			for (; d < c; d++) {
				if (e.indexOf(" " + b[d] + " ") < 0) {
					a += (a ? " " : "") + b[d]
				}
			}
			f.className = a;
			return f
		};
		baidu.addClass = baidu.dom.addClass;
		baidu.dom.removeClass = function(f, g) {
			f = baidu.dom.g(f);
			var d = f.className.split(/\s+/), h = g.split(/\s+/), b, a = h.length, c, e = 0;
			for (; e < a; ++e) {
				for (c = 0, b = d.length; c < b; ++c) {
					if (d[c] == h[e]) {
						d.splice(c, 1);
						break
					}
				}
			}
			f.className = d.join(" ");
			return f
		};
		baidu.removeClass = baidu.dom.removeClass;
		baidu.dom.hasClass = function(c, d) {
			c = baidu.dom.g(c);
			var b = baidu.string.trim(d).split(/\s+/), a = b.length;
			d = c.className.split(/\s+/).join(" ");
			while (a--) {
				if (!(new RegExp("(^| )" + b[a] + "( |\x24)")).test(d)) {
					return false
				}
			}
			return true
		};
		baidu.event.getTarget = function(a) {
			return a.target || a.srcElement
		};
		baidu.array = baidu.array || {};
		baidu.each = baidu.array.forEach = baidu.array.each = function(g, e, b) {
			var d, f, c, a = g.length;
			if ("function" == typeof e) {
				for (c = 0; c < a; c++) {
					f = g[c];
					d = e.call(b || g, f, c);
					if (d === false) {
						break
					}
				}
			}
			return g
		};
		baidu.object.each = function(e, c) {
			var b, a, d;
			if ("function" == typeof c) {
				for (a in e) {
					if (e.hasOwnProperty(a)) {
						d = e[a];
						b = c.call(e, d, a);
						if (b === false) {
							break
						}
					}
				}
			}
			return e
		};
		baidu.fn = baidu.fn || {};
		baidu.fn.bind = function(b, a) {
			var c = arguments.length > 2 ? [].slice.call(arguments, 2) : null;
			return function() {
				var e = baidu.lang.isString(b) ? a[b] : b, d = (c) ? c
						.concat([].slice.call(arguments, 0)) : arguments;
				return e.apply(a || e, d)
			}
		};
		baidu.lang.Class.prototype.addEventListeners = function(c, d) {
			if (typeof d == "undefined") {
				for (var b in c) {
					this.addEventListener(b, c[b])
				}
			} else {
				c = c.split(",");
				var b = 0, a = c.length, e;
				for (; b < a; b++) {
					this.addEventListener(baidu.trim(c[b]), d)
				}
			}
		};
		(function() {
			var a = baidu.ui.behavior.statable = function() {
				var b = this;
				b.addEventListeners("ondisable,onenable", function(e, c) {
							var d, f;
							c = c || {};
							elementId = (c.element || b.getMain()).id;
							f = c.group;
							if (e.type == "ondisable"
									&& !b.getState(elementId, f)["disabled"]) {
								b.removeState("press", elementId, f);
								b.removeState("hover", elementId, f);
								b.setState("disabled", elementId, f)
							} else {
								if (e.type == "onenable"
										&& b.getState(elementId, f)["disabled"]) {
									b.removeState("disabled", elementId, f)
								}
							}
						})
			};
			a._states = {};
			a._allStates = ["hover", "press", "disabled"];
			a._allEventsName = ["mouseover", "mouseout", "mousedown", "mouseup"];
			a._eventsHandler = {
				mouseover : function(d, c) {
					var b = this;
					if (!b.getState(d, c)["disabled"]) {
						b.setState("hover", d, c);
						return true
					}
				},
				mouseout : function(d, c) {
					var b = this;
					if (!b.getState(d, c)["disabled"]) {
						b.removeState("hover", d, c);
						b.removeState("press", d, c);
						return true
					}
				},
				mousedown : function(d, c) {
					var b = this;
					if (!b.getState(d, c)["disabled"]) {
						b.setState("press", d, c);
						return true
					}
				},
				mouseup : function(d, c) {
					var b = this;
					if (!b.getState(d, c)["disabled"]) {
						b.removeState("press", d, c);
						return true
					}
				}
			};
			a._getStateHandlerString = function(h, f) {
				var g = this, e = 0, b = g._allEventsName.length, c = [], d;
				if (typeof h == "undefined") {
					h = f = ""
				}
				for (; e < b; e++) {
					d = g._allEventsName[e];
					c[e] = "on" + d + '="' + g.getCallRef() + "._fireEvent('"
							+ d + "', '" + h + "', '" + f + "', event)\""
				}
				return c.join(" ")
			};
			a._fireEvent = function(c, g, b, f) {
				var d = this, h = d.getId(g + b);
				if (d._eventsHandler[c].call(d, h, g)) {
					d.dispatchEvent(c, {
								element : h,
								group : g,
								key : b,
								DOMEvent : f
							})
				}
			};
			a.addState = function(e, b, c) {
				var d = this;
				d._allStates.push(e);
				if (b) {
					d._allEventsName.push(b);
					if (!c) {
						c = function() {
							return true
						}
					}
					d._eventsHandler[b] = c
				}
			};
			a.getState = function(b, e) {
				var d = this, c;
				e = e ? e + "-" : "";
				b = b ? b : d.getId();
				c = d._states[e + b];
				return c ? c : {}
			};
			a.setState = function(e, b, f) {
				var d = this, g, c;
				f = f ? f + "-" : "";
				b = b ? b : d.getId();
				g = f + b;
				d._states[g] = d._states[g] || {};
				c = d._states[g][e];
				if (!c) {
					d._states[g][e] = 1;
					baidu.addClass(b, d.getClass(f + e))
				}
			};
			a.removeState = function(d, b, e) {
				var c = this, f;
				e = e ? e + "-" : "";
				b = b ? b : c.getId();
				f = e + b;
				if (c._states[f]) {
					c._states[f][d] = 0;
					baidu.removeClass(b, c.getClass(e + d))
				}
			}
		})();
		baidu.browser = baidu.browser || {};
		baidu.browser.opera = /opera(\/| )(\d+(\.\d+)?)(.+?(version\/(\d+(\.\d+)?)))?/i
				.test(navigator.userAgent)
				? +(RegExp["\x246"] || RegExp["\x242"])
				: undefined;
		baidu.dom.insertHTML = function(d, a, c) {
			d = baidu.dom.g(d);
			var b, e;
			if (d.insertAdjacentHTML && !baidu.browser.opera) {
				d.insertAdjacentHTML(a, c)
			} else {
				b = d.ownerDocument.createRange();
				a = a.toUpperCase();
				if (a == "AFTERBEGIN" || a == "BEFOREEND") {
					b.selectNodeContents(d);
					b.collapse(a == "AFTERBEGIN")
				} else {
					e = a == "BEFOREBEGIN";
					b[e ? "setStartBefore" : "setEndAfter"](d);
					b.collapse(e)
				}
				b.insertNode(b.createContextualFragment(c))
			}
			return d
		};
		baidu.insertHTML = baidu.dom.insertHTML;
		baidu.string.format = function(c, a) {
			c = String(c);
			var b = Array.prototype.slice.call(arguments, 1), d = Object.prototype.toString;
			if (b.length) {
				b = b.length == 1 ? (a !== null
						&& (/\[object Array\]|\[object Object\]/
								.test(d.call(a))) ? a : b) : b;
				return c.replace(/#\{(.+?)\}/g, function(e, g) {
							var f = b[g];
							if ("[object Function]" == d.call(f)) {
								f = f(g)
							}
							return ("undefined" == typeof f ? "" : f)
						})
			}
			return c
		};
		baidu.format = baidu.string.format;
		baidu.ui.Base.setParent = function(b) {
			var c = this, a = c._parent;
			a && a.dispatchEvent("removechild");
			if (b.dispatchEvent("appendchild", {
						child : c
					})) {
				c._parent = b
			}
		};
		baidu.ui.Base.getParent = function() {
			return this._parent || null
		};
		baidu.browser.ie = baidu.ie = /msie (\d+\.\d+)/i
				.test(navigator.userAgent)
				? (document.documentMode || +RegExp["\x241"])
				: undefined;
		baidu.dom.remove = function(a) {
			a = baidu.dom._g(a);
			var b = a.parentNode;
			b && b.removeChild(a)
		};
		baidu.ui.Button = baidu.ui.createUI(new Function).extend({
			uiType : "button",
			tplBody : '<div id="#{id}" #{statable} class="#{class}">#{content}</div>',
			disabled : false,
			statable : true,
			_getString : function() {
				var a = this;
				return baidu.format(a.tplBody, {
							id : a.getId(),
							statable : a._getStateHandlerString(),
							"class" : a.getClass(),
							content : a.content
						})
			},
			render : function(c) {
				var b = this, a;
				b.addState("click", "click");
				baidu.dom.insertHTML(b.renderMain(c), "beforeEnd", b
								._getString());
				a = baidu.g(c).lastChild;
				if (b.title) {
					a.title = b.title
				}
				b.disabled && b.setState("disabled");
				b.dispatchEvent("onload")
			},
			isDisabled : function() {
				var a = this, b = a.getId();
				return a.getState()["disabled"]
			},
			dispose : function() {
				var b = this, a = b.getBody();
				b.dispatchEvent("dispose");
				baidu.each(b._allEventsName, function(d, c) {
							a["on" + d] = null
						});
				baidu.dom.remove(a);
				b.dispatchEvent("ondispose");
				baidu.lang.Class.prototype.dispose.call(b)
			},
			disable : function() {
				var b = this, a = b.getBody();
				b.dispatchEvent("ondisable", {
							element : a
						})
			},
			enable : function() {
				var a = this;
				body = a.getBody();
				a.dispatchEvent("onenable", {
							element : body
						})
			},
			fire : function(a, c) {
				var b = this, a = a.toLowerCase();
				if (b.getState()["disabled"]) {
					return
				}
				b._fireEvent(a, null, null, c)
			},
			update : function(a) {
				var b = this;
				baidu.extend(b, a);
				a.content && (b.getBody().innerHTML = a.content);
				b.dispatchEvent("onupdate")
			}
		});
		baidu.lang.isBoolean = function(a) {
			return typeof a === "boolean"
		};
		baidu.ui.Button.register(function(a) {
			if (!a.poll) {
				return
			}
			baidu.lang.isBoolean(a.poll) && (a.poll = {});
			a.addEventListener("mousedown", function(b) {
						var d = 0, c = a.poll.interval || 100, e = a.poll.time
								|| 0;
			(function	() {
							if (a.getState()["press"]) {
								d++ > e && a.onmousedown && a.onmousedown();
								a.poll.timeOut = setTimeout(arguments.callee, c)
							}
						})()
					});
			a.addEventListener("dispose", function() {
						if (a.poll.timeOut) {
							a.disable();
							window.clearTimeout(a.poll.timeOut)
						}
					})
		});
		baidu.date = baidu.date || {};
		baidu.number = baidu.number || {};
		baidu.number.pad = function(d, c) {
			var e = "", b = (d < 0), a = String(Math.abs(d));
			if (a.length < c) {
				e = (new Array(c - a.length + 1)).join("0")
			}
			return (b ? "-" : "") + e + a
		};
		baidu.date.format = function(a, f) {
			if ("string" != typeof f) {
				return a.toString()
			}
			function d(l, k) {
				f = f.replace(l, k)
			}
			var b = baidu.number.pad, g = a.getFullYear(), e = a.getMonth() + 1, j = a
					.getDate(), h = a.getHours(), c = a.getMinutes(), i = a
					.getSeconds();
			d(/yyyy/g, b(g, 4));
			d(/yy/g, b(parseInt(g.toString().slice(2), 10), 2));
			d(/MM/g, b(e, 2));
			d(/M/g, e);
			d(/dd/g, b(j, 2));
			d(/d/g, j);
			d(/HH/g, b(h, 2));
			d(/H/g, h);
			d(/hh/g, b(h % 12, 2));
			d(/h/g, h % 12);
			d(/mm/g, b(c, 2));
			d(/m/g, c);
			d(/ss/g, b(i, 2));
			d(/s/g, i);
			return f
		};
		baidu.array.indexOf = function(e, b, d) {
			var a = e.length, c = b;
			d = d | 0;
			if (d < 0) {
				d = Math.max(0, a + d)
			}
			for (; d < a; d++) {
				if (d in e && e[d] === b) {
					return d
				}
			}
			return -1
		};
		baidu.array.some = function(e, d, b) {
			var c = 0, a = e.length;
			for (; c < a; c++) {
				if (c in e && d.call(b || e, e[c], c)) {
					return true
				}
			}
			return false
		};
		baidu.lang.isDate = function(a) {
			return {}.toString.call(a) === "[object Date]"
					&& a.toString() !== "Invalid Date" && !isNaN(a)
		};
		baidu.lang.isNumber = function(a) {
			return "[object Number]" == Object.prototype.toString.call(a)
					&& isFinite(a)
		};
		baidu.i18n = baidu.i18n || {};
		baidu.i18n.cultures = baidu.i18n.cultures || {};
		baidu.i18n.cultures["zh-CN"] = baidu.object.extend(
				baidu.i18n.cultures["zh-CN"] || {}, {
					calendar : {
						dateFormat : "yyyy-MM-dd",
						titleNames : "#{yyyy}年&nbsp;#{MM}月",
						monthNames : ["一", "二", "三", "四", "五", "六", "七", "八",
								"九", "十", "十一", "十二"],
						dayNames : {
							mon : "一",
							tue : "二",
							wed : "三",
							thu : "四",
							fri : "五",
							sat : "六",
							sun : "日"
						}
					},
					timeZone : 8,
					whitespace : new RegExp(
							"(^[\\s\\t\\xa0\\u3000]+)|([\\u3000\\xa0\\s\\t]+\x24)",
							"g"),
					number : {
						group : ",",
						groupLength : 3,
						decimal : ".",
						positive : "",
						negative : "-",
						_format : function(b, a) {
							return baidu.i18n.number._format(b, {
										group : this.group,
										groupLength : this.groupLength,
										decimal : this.decimal,
										symbol : a
												? this.negative
												: this.positive
									})
						}
					},
					currency : {
						symbol : "￥"
					},
					language : {
						ok : "确定",
						cancel : "取消",
						signin : "注册",
						signup : "登录"
					}
				});
		baidu.i18n.currentLocale = baidu.i18n.currentLocale || "zh-CN";
		baidu.i18n.date = baidu.i18n.date || {
			getDaysInMonth : function(a, b) {
				var c = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
				if (b == 1 && baidu.i18n.date.isLeapYear(a)) {
					return 29
				}
				return c[b]
			},
			isLeapYear : function(a) {
				return !(a % 400) || (!(a % 4) && !!(a % 100))
			},
			toLocaleDate : function(b, a, c) {
				return this._basicDate(b, a, c || baidu.i18n.currentLocale)
			},
			_basicDate : function(f, c, h) {
				var a = baidu.i18n.cultures[h || baidu.i18n.currentLocale].timeZone, g = a
						* 60, b, d, e = f.getTime();
				if (c) {
					b = baidu.i18n.cultures[c].timeZone;
					d = b * 60
				} else {
					d = -1 * f.getTimezoneOffset();
					b = b / 60
				}
				return new Date(b != a ? (e + (g - d) * 60000) : e)
			}
		};
		baidu.ui.Calendar = baidu.ui.createUI(function(a) {
			var b = this;
			b.flipContent = baidu.object.extend({
						prev : "&lt;",
						next : "&gt;"
					}, b.flipContent);
			b.addEventListener("mouseup", function(c) {
						var f = c.element, d = b._dates[f], e = baidu.dom
								.g(b._currElementId);
						e
								&& baidu.dom.removeClass(e, b
												.getClass("date-current"));
						b._currElementId = f;
						b._initDate = d;
						baidu.dom.addClass(baidu.dom.g(f), b
										.getClass("date-current"));
						b.dispatchEvent("clickdate", {
									date : d
								})
					})
		}).extend({
			uiType : "calendar",
			weekStart : "Sun",
			statable : true,
			language : "zh-CN",
			tplDOM : '<div id="#{id}" class="#{class}">#{content}</div>',
			tplTable : '<table border="0" cellpadding="0" cellspacing="1" class="#{class}"><thead class="#{headClass}">#{head}</thead><tbody class="#{bodyClass}">#{body}</tbody></table>',
			tplDateCell : '<td id="#{id}" class="#{class}" #{handler}>#{content}</td>',
			tplTitle : '<div id="#{id}" class="#{class}"><div id="#{labelId}" class="#{labelClass}">#{text}</div><div id="#{prevId}" class="#{prevClass}"></div><div id="#{nextId}" class="#{nextClass}"></div></div>',
			_initialize : function() {
				var a = this;
				function b(d) {
					var c = [];
					baidu.array.each(d, function(e) {
								c.push(baidu.lang.isDate(e)
										? a._toLocalDate(e)
										: {
											start : a._toLocalDate(e.start),
											end : a._toLocalDate(e.end)
										})
							});
					return c
				}
				a._highlightDates = b(a.highlightDates || []);
				a._disableDates = b(a.disableDates || []);
				a._initDate = a._toLocalDate(a.initDate || new Date());
				a._currDate = new Date(a._initDate.getTime());
				a.weekStart = a.weekStart.toLowerCase()
			},
			_getDateJson : function(b) {
				var f = this, a = baidu.lang.guid(), h = f._currDate, d = [], e;
				function g(j, i) {
					return j.getDate() == i.getDate()
							&& Math.abs(j.getTime() - i.getTime()) < 24 * 60
									* 60 * 1000
				}
				function c(k, i) {
					var j = i.getTime();
					return baidu.array.some(k, function(l) {
								if (baidu.lang.isDate(l)) {
									return g(l, i)
								} else {
									return g(l.start, i)
											|| j > l.start.getTime()
											&& j <= l.end.getTime()
								}
							})
				}
				b.getMonth() != h.getMonth()
						&& d.push(f.getClass("date-other"));
				c(f._highlightDates, b) && d.push(f.getClass("date-highlight"));
				if (g(f._initDate, b)) {
					d.push(f.getClass("date-current"));
					f._currElementId = f.getId(a)
				}
				g(f._toLocalDate(new Date()), b)
						&& d.push(f.getClass("date-today"));
				e = c(f._disableDates, b) && (d = []);
				return {
					id : f.getId(a),
					"class" : d.join("\x20"),
					handler : f._getStateHandlerString("", a),
					date : b,
					disabled : e
				}
			},
			_getMonthCount : function(c, e) {
				var a = baidu.i18n.date.getDaysInMonth, b = [31, 28, 31, 30,
						31, 30, 31, 31, 30, 31, 30, 31], d;
				a && (d = a(c, e));
				if (!baidu.lang.isNumber(d)) {
					d = 1 == e && (c % 4) && (c % 100 != 0 || c % 400 == 0)
							? 29
							: b[e]
				}
				return d
			},
			_getDateTableString : function() {
				var o = this, f = baidu.i18n.cultures[o.language].calendar, a = [
						"sun", "mon", "tue", "wed", "thu", "fri", "sat"], s = o._currDate, p = s
						.getFullYear(), n = s.getMonth(), q = new Date(p, n, 1)
						.getDay(), g = 0, e = [], m = [], h = [], r = o._disabledIds = [], d = 0, c = 0, l = a.length, k, b;
				for (; d < l; d++) {
					a[d] == o.weekStart && (g = d);
					(g > 0 ? e : h).push("<td>", f.dayNames[a[d]], "</td>")
				}
				e = e.concat(h);
				e.unshift("<tr>");
				e.push("</tr>");
				q = (q < g ? q + 7 : q) - g;
				k = Math.ceil((o._getMonthCount(p, n) + q) / l);
				o._dates = {};
				for (d = 0; d < k; d++) {
					m.push("<tr>");
					for (c = 0; c < l; c++) {
						b = o._getDateJson(new Date(p, n, d * l + c + 1 - q));
						o._dates[b.id] = b.date;
						b.disabled && r.push(b.id);
						m.push(baidu.string.format(o.tplDateCell, {
									id : b.id,
									"class" : b["class"],
									handler : b.handler,
									content : b.date.getDate()
								}))
					}
					m.push("</tr>")
				}
				return baidu.string.format(o.tplTable, {
							"class" : o.getClass("table"),
							headClass : o.getClass("week"),
							bodyClass : o.getClass("date"),
							head : e.join(""),
							body : m.join("")
						})
			},
			getString : function() {
				var a = this;
				return baidu.string.format(a.tplDOM, {
							id : a.getId(),
							"class" : a.getClass(),
							content : baidu.string.format(a.tplDOM, {
										id : a.getId("content"),
										"class" : a.getClass("content")
									})
						})
			},
			_toLocalDate : function(a) {
				return a
						? baidu.i18n.date.toLocaleDate(a, null, this.language)
						: a
			},
			_renderDate : function() {
				var a = this;
				baidu.dom.g(a.getId("content")).innerHTML = a
						._getDateTableString();
				baidu.array.each(a._disabledIds, function(b) {
							a.setState("disabled", b)
						})
			},
			_basicFlipMonth : function(e) {
				var b = this, d = b._currDate, c = d.getMonth()
						+ (e == "prev" ? -1 : 1), a = d.getFullYear()
						+ (c < 0 ? -1 : (c > 11 ? 1 : 0));
				c = c < 0 ? 12 : (c > 11 ? 0 : c);
				d.setYear(a);
				b.gotoMonth(c);
				b.dispatchEvent(e + "month", {
							date : new Date(d.getTime())
						})
			},
			renderTitle : function() {
				var e = this, d, c, h = e._currDate, g = baidu.i18n.cultures[e.language].calendar, f = baidu.dom
						.g(e.getId("label")), a = baidu.string.format(
						g.titleNames, {
							yyyy : h.getFullYear(),
							MM : g.monthNames[h.getMonth()],
							dd : h.getDate()
						});
				if (f) {
					f.innerHTML = a;
					return
				}
				baidu.dom.insertHTML(e.getBody(), "afterBegin", baidu.string
								.format(e.tplTitle, {
											id : e.getId("title"),
											"class" : e.getClass("title"),
											labelId : e.getId("label"),
											labelClass : e.getClass("label"),
											text : a,
											prevId : e.getId("prev"),
											prevClass : e.getClass("prev"),
											nextId : e.getId("next"),
											nextClass : e.getClass("next")
										}));
				function b(i) {
					return {
						classPrefix : e.classPrefix + "-" + i + "btn",
						skin : e.skin ? e.skin + "-" + i : "",
						content : e.flipContent[i],
						poll : {
							time : 4
						},
						element : e.getId(i),
						autoRender : true,
						onmousedown : function() {
							e._basicFlipMonth(i)
						}
					}
				}
				d = new baidu.ui.Button(b("prev"));
				c = new baidu.ui.Button(b("next"));
				e.addEventListener("ondispose", function() {
							d.dispose();
							c.dispose()
						})
			},
			render : function(c) {
				var a = this, b = a.skin;
				if (!c || a.getMain()) {
					return
				}
				baidu.dom.insertHTML(a.renderMain(c), "beforeEnd", a
								.getString());
				a._initialize();
				a.renderTitle();
				a._renderDate();
				baidu.dom.g(a.getId("content")).style.height = (a.getBody().clientHeight || a
						.getBody().offsetHeight)
						- baidu.dom.g(a.getId("title")).offsetHeight + "px";
				a.dispatchEvent("onload")
			},
			update : function(a) {
				var b = this;
				baidu.object.extend(b, a || {});
				b._initialize();
				b.renderTitle();
				b._renderDate();
				b.dispatchEvent("onupdate")
			},
			gotoDate : function(a) {
				var b = this;
				b._currDate = b._toLocalDate(a);
				b._initDate = b._toLocalDate(a);
				b.renderTitle();
				b._renderDate();
				b.dispatchEvent("ongotodate")
			},
			gotoYear : function(b) {
				var d = this, f = d._currDate, e = f.getMonth(), a = f
						.getDate(), c;
				if (1 == e) {
					c = d._getMonthCount(b, e);
					a > c && f.setDate(c)
				}
				f.setFullYear(b);
				d.renderTitle();
				d._renderDate();
				d.dispatchEvent("ongotoyear")
			},
			gotoMonth : function(e) {
				var c = this, d = c._currDate, e = Math.min(Math.max(e, 0), 11), a = d
						.getDate(), b = c._getMonthCount(d.getFullYear(), e);
				a > b && d.setDate(b);
				d.setMonth(e);
				c.renderTitle();
				c._renderDate();
				c.dispatchEvent("ongotomonth")
			},
			getToday : function() {
				return me._toLocalDate(new Date())
			},
			getDate : function() {
				return new Date(this._initDate.getTime())
			},
			setDate : function(a) {
				if (baidu.lang.isDate(a)) {
					var b = this;
					b._initDate = a;
					b._currDate = a
				}
			},
			prevMonth : function() {
				this._basicFlipMonth("prev")
			},
			nextMonth : function() {
				this._basicFlipMonth("next")
			},
			dispose : function() {
				var a = this;
				a.dispatchEvent("dispose");
				baidu.dom.remove(a.getMain());
				baidu.lang.Class.prototype.dispose.call(a)
			}
		});
		TCalendar = baidu.ui.Calendar;
		Tformat = baidu.date.format;
	})();

	var DatePickerPopup = function(options) {
		this.initOptions(options);
		this.initPopup();
		var me = this;
		this._calendar = new TCalendar({
					onclickdate : function(evt) {
						me.fireEvent('pickdate', evt.date);
					}
				});
	};
	DatePickerPopup.prototype = {
		content : '',
		_Popup_postRender : Popup.prototype.postRender,
		postRender : function() {
			this._calendar.render(this.getDom('content'));
			this._Popup_postRender();
		}
	};
	utils.inherits(DatePickerPopup, Popup);

	var DateButton = baidu.editor.ui.DateButton = function(options) {
		this.initOptions(options);
		this.initDateButton();
	};
	DateButton.prototype = {
		initDateButton : function() {
			var me = this;
			this.popup = new DatePickerPopup({
				onpickdate : function(t, date) {
					if (me.fireEvent('pickdate', Tformat(date, 'yyyy-MM-dd')) !== false) {
						me.popup.hide();
					}
				}
			});
			this.initSplitButton();
		}
	};
	utils.inherits(DateButton, SplitButton);
})();